using System;
using System.Web;

//using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace Framework.Library.Core.Utils.Web.Modules
{
    public class ErrorModule : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.Error += Error;
        }

        #endregion

        private void Error(object sender, EventArgs e)
        {
            var application = (HttpApplication) sender;
            HttpContext context = application.Context;

            Exception ex = context.Server.GetLastError();

            // unwrap unhandled exception
            if (ex is HttpUnhandledException && ex.InnerException != null)
                ex = ex.InnerException;

            bool rethrow = true; //ExceptionPolicy.HandleException(ex, "Exception Policy");

            if (!rethrow)
                context.Server.ClearError();
        }
    }
}